package com.punch.course.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punch.common.dto.course.CourseAuditDTO;
import com.punch.common.dto.course.CourseDTO;
import com.punch.common.dto.course.CourseLessonsDTO;
import com.punch.common.dto.user.user.RedisUserDTO;
import com.punch.common.enums.user.role.UserRoleEnum;
import com.punch.common.enums.user.user.AuditStatusEnum;
import com.punch.common.exception.BusinessException;
import com.punch.common.feign.FeignAreaService;
import com.punch.common.feign.FeignClassService;
import com.punch.common.feign.FeignUserService;
import com.punch.common.page.PageInfo;
import com.punch.common.redis.utils.UserUtil;
import com.punch.common.tools.BasePage;
import com.punch.common.utils.ImageUtil;
import com.punch.common.vo.course.*;
import com.punch.common.vo.course.report.CourseReportVO;
import com.punch.common.vo.course.report.OrganReportVO;
import com.punch.common.vo.system.category.CategoryTreeVO;
import com.punch.common.vo.user.user.UserExtendVO;
import com.punch.course.exception.CourseExceptionEnum;
import com.punch.course.mapper.CourseMapper;
import com.punch.course.model.*;
import com.punch.course.query.CourseQueryInfo;
import com.punch.course.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;


/**
 * CourseService-课程信息 服务类
 *
 * @author xiaol
 * @version 1.0.0
 * @since 2020/7/14 10:51
 */
@Service
@Deprecated
public class CourseServiceImpl extends ServiceImpl<CourseMapper, PunchCourse> implements CourseService {

    @Resource
    private CourseLessonsService courseLessonsService;

    @Resource
    private FeignClassService feignClassService;

    @Resource
    private FeignAreaService feignAreaService;

    @Resource
    private FeignUserService feignUserService;

    @Resource
    private CourseAuditLogService courseAuditLogService;

    @Resource
    private CourseTeachingService courseTeachingService;

    @Resource
    private CategoryService categoryService;
//
//    @Resource
//    private ClassService classService;

    /**
     * 条件分页查询课程列表
     *
     * @return 课程信息
     */
    @Override
    public PageInfo<CoursePageVO> listCourse(CourseQueryInfo queryInfo) {
        //教育局的查看审核中的
        if (queryInfo.getCurrentRoleId() == UserRoleEnum.EDUCATION.getCode() || queryInfo.getCurrentRoleId() == UserRoleEnum.MANAGER.getCode()) {
            setChildAreaList(queryInfo);
        }
        //学校查看自己的课程与机构申请授课的课程
        if (queryInfo.getCurrentRoleId() == UserRoleEnum.SCHOOL.getCode()) {
            Long userId = UserUtil.getLoginUserId();
            queryInfo.setCreateId(userId);
            QueryWrapper<CourseTeaching> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(CourseTeaching::getSchoolId, userId).eq(CourseTeaching::getStatus, 0);
            List<CourseTeaching> list = courseTeachingService.list(queryWrapper);
            if (CollUtil.isNotEmpty(list)) {
                List<Long> teachingToSchoolIdList = new ArrayList<>();
                list.forEach(courseTeaching -> teachingToSchoolIdList.add(courseTeaching.getCourseId()));
                //  queryInfo.setTeachingToSchoolIdList(teachingToSchoolIdList);
            }
        }
        //机构查看自己的课程
        if (queryInfo.getCurrentRoleId() == UserRoleEnum.ORGAN.getCode()) {
            queryInfo.setCreateId(UserUtil.getLoginUserId());
        }


        return BasePage.queryBasePage(queryInfo, params -> this.getBaseMapper().queryCount(params),
                params -> this.getBaseMapper().queryList(params));
    }


    /**
     * 查询课程详情
     *
     * @param courseId 课程id
     * @return 课程详情
     */
    @Override
    public CourseVO getCourseById(Long courseId) {
        PunchCourse course = getById(courseId);
        if (course == null) {
            throw new BusinessException(CourseExceptionEnum.COURSE_DETAIL_FAIL_NULL);
        }
        CourseVO courseVO = new CourseVO();
        BeanUtils.copyProperties(course, courseVO);
        //适用年级 courseGrade
        if (StringUtils.isNotEmpty(course.getCourseGrade())) {
            String[] courseGradeArray = course.getCourseGrade().split(",");
            List<Integer> courseGradeList = new ArrayList<>();
            for (String courseGrade : courseGradeArray) {
                courseGradeList.add(Integer.valueOf(courseGrade));
            }
            courseVO.setCourseGrade(courseGradeList);
        }

        //课程类目id course_category_id 单独处理
        if (StringUtils.isNotEmpty(course.getCourseCategoryId())) {
            String[] courseCategoryIdArray = course.getCourseCategoryId().split(",");
            List<Long> courseCategoryIdkList = new ArrayList<>();
            for (String courseCategoryId : courseCategoryIdArray) {
                courseCategoryIdkList.add(Long.valueOf(courseCategoryId));
            }
            courseVO.setCourseCategoryId(courseCategoryIdkList);
        }

        //根据课程内容id查询对应的课程内容（可能有多条，用集合接收）
        QueryWrapper<CourseLessons> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CourseLessons::getCourseId, courseId);
        List<CourseLessons> contentList = courseLessonsService.list(queryWrapper);
        if (CollUtil.isNotEmpty(contentList)) {
            List<CourseContentVO> courseContentList = new ArrayList<>();
            contentList.forEach(punchCourseContent -> {
                CourseContentVO courseContentVO = new CourseContentVO();
                courseContentVO.setLessonsTitle(punchCourseContent.getLessonsTitle());
                courseContentVO.setLessonsContent(punchCourseContent.getLessonsContent());
                courseContentList.add(courseContentVO);
            });
            courseVO.setCourseContentList(courseContentList);

        }

        if (StrUtil.isNotEmpty(course.getCourseImg())) {
            courseVO.setCourseImg(ImageUtil.addPrefix(course.getCourseImg()));
        }
        courseVO.setCourseId(courseId);
        return courseVO;
    }

    /**
     * 新增课程信息
     *
     * @param courseDTO 表单数据
     * @return 新增课程记录id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long saveCourse(CourseDTO courseDTO) {
        PunchCourse punchCourse = new PunchCourse();
        //保存课程基本信息
        BeanUtils.copyProperties(courseDTO, punchCourse);
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        //当前用户地区id
        Integer currentUserAreaId = loginUser.getAreaId();
        //当前用户地区
        String currentUserAreaName = loginUser.getAreaName();
        //当前用户id
        Long currentUserId = loginUser.getUserId();
        //当前用户角色id
        Integer currentUserRoleId = loginUser.getRoleId();
        //获取用户名称
        String createName = loginUser.getUsername();
        punchCourse.setCreateId(currentUserId);
        punchCourse.setCreateName(createName);
        punchCourse.setRoleId(currentUserRoleId);
        punchCourse.setAreaId(currentUserAreaId);
        punchCourse.setAreaName(currentUserAreaName);
        handlerGrade(punchCourse, courseDTO);
        //学校创建的课程直接审核通过
        if (currentUserRoleId == UserRoleEnum.SCHOOL.getCode()) {
            punchCourse.setCourseStatus(AuditStatusEnum.PASSED.getCode());
        }
        //机构创建课程插入机构编号
        if (currentUserRoleId == UserRoleEnum.ORGAN.getCode()) {
            UserExtendVO orgExtend = feignUserService.getUserSettlement(currentUserId, 1).getData();
            punchCourse.setOrgNo(orgExtend.getOrgNo());
        }
        if (StrUtil.isEmpty(courseDTO.getCourseSiteRequirements())) {
            punchCourse.setCourseSiteRequirements("");
        }
        if (StrUtil.isEmpty(courseDTO.getCourseIntroduce())) {
            punchCourse.setCourseIntroduce("");
        }

        //处理图片
        if (StrUtil.isNotEmpty(courseDTO.getCourseImg())) {
            punchCourse.setCourseImg(ImageUtil.removePrefix(courseDTO.getCourseImg()));
        }
        if (!save(punchCourse)) {
            throw new BusinessException(CourseExceptionEnum.COURSE_SAVE_FAIL);
        }
        if (CollUtil.isNotEmpty(courseDTO.getCourseContentList())) {
            insertCourseContent(punchCourse.getId(), courseDTO.getCourseContentList());
        }
        return punchCourse.getId();
    }

    /**
     * 编辑课程信息
     *
     * @param courseDTO 表单数据
     * @return 编辑课程记录id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long updateCourse(CourseDTO courseDTO) {
        PunchCourse punchCourseEX = getById(courseDTO.getCourseId());
        if (punchCourseEX == null) {
            throw new BusinessException(CourseExceptionEnum.COURSE_EDIT_FAIL);
        }
        PunchCourse punchCourse = new PunchCourse();
        //修改课程基本信息
        BeanUtils.copyProperties(courseDTO, punchCourse);
        //查看课程类目是否变化
//        if (courseDTO.getCourseCategoryId() != punchCourseEX.getCourseCategoryId()) {
//            //获取课程类目名称 todo
//            punchCourse.setCourseCategoryName("测试课程类目");
//        }
        //处理图片
        if (StrUtil.isNotEmpty(courseDTO.getCourseImg())) {
            punchCourse.setCourseImg(ImageUtil.removePrefix(courseDTO.getCourseImg()));
        } else {
            punchCourse.setCourseImg("");
        }
        punchCourse.setId(courseDTO.getCourseId());
        handlerGrade(punchCourse, courseDTO);
        if (StrUtil.isEmpty(courseDTO.getCourseSiteRequirements())) {
            punchCourse.setCourseSiteRequirements("");
        }
        if (StrUtil.isEmpty(courseDTO.getCourseIntroduce())) {
            punchCourse.setCourseIntroduce("");
        }
        updateById(punchCourse);
        //删除课程内容信息（软删除）
        UpdateWrapper<CourseLessons> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(CourseLessons::getCourseId, courseDTO.getCourseId());
        courseLessonsService.remove(updateWrapper);
        if (CollUtil.isNotEmpty(courseDTO.getCourseContentList())) {
            insertCourseContent(punchCourse.getId(), courseDTO.getCourseContentList());
        }
        return punchCourse.getId();
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteCourseById(Long courseId) {
        PunchCourse temp = getById(courseId);
        if (temp == null) {
            throw new BusinessException(CourseExceptionEnum.COURSE_DEL_FAIL_NULL);
        }
        removeById(courseId);
        //删除课节内容
        UpdateWrapper<CourseLessons> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(CourseLessons::getCourseId, courseId);
        courseLessonsService.remove(updateWrapper);

    }


    /**
     * 课程下拉列表--只找课程库里面的课程
     *
     * @param courseName 课程名称
     * @return List<SimpleCourseVO> 课程下拉列表
     */
    @Override
    public List<SimpleCourseVO> listCourseSelect(String courseName, Long courseId) {
        Long currentUid = UserUtil.getLoginUser().getUserId();
        if (courseId != null && courseId.intValue() != 0) {
            //查找该课程的创建者
            //currentUid = classService.getById(courseId).getCreateId();
        }
        return getBaseMapper().listSimpleCourse(courseName, currentUid);
    }

    /**
     * 课程启用/停用
     *
     * @param courseId 课程id
     */
    @Override
    public void enableCourse(Long courseId) {
        PunchCourse courseEX = getById(courseId);
        if (courseEX == null) {
            throw new BusinessException(CourseExceptionEnum.COURSE_DETAIL_FAIL_NULL);
        }
        PunchCourse updateCourse = new PunchCourse();
        //启用变成停用
        if (courseEX.getEnabled() == 1) {
            updateCourse.setEnabled(0);
        }
        //停用变成启用
        if (courseEX.getEnabled() == 0) {
            updateCourse.setEnabled(1);
        }
        updateCourse.setId(courseId);
        updateById(updateCourse);
    }

    /**
     * 课程审核
     *
     * @param courseAuditDTO 课程审批表单
     */
    @Override
    public void auditCourse(CourseAuditDTO courseAuditDTO) {
        //当前登录用户角色id
        RedisUserDTO redisUserDTO = UserUtil.getLoginUser();
        Integer currentRoleId = redisUserDTO.getRoleId();
        PunchCourse punchCourse = getById(courseAuditDTO.getCourseId());
        Optional.ofNullable(punchCourse).orElseThrow(() -> new BusinessException(CourseExceptionEnum.COURSE_DETAIL_FAIL_NULL));
        verifyStatus(courseAuditDTO.getCourseStatus(), punchCourse.getCourseStatus(), currentRoleId);
        PunchCourse bean = new PunchCourse();
        bean.setId(courseAuditDTO.getCourseId());
        //如果是机构,查看且没有审核成功,教师提交审核状态为(机构待审核提交),确保机构用户在教师列表查询不到该数据
        if (currentRoleId.equals(UserRoleEnum.ORGAN.getCode()) && !redisUserDTO.getAuditStatus().equals(AuditStatusEnum.PASSED.getCode())) {
            bean.setCourseStatus(AuditStatusEnum.ORG_UN_AUDIT_COMMIT.getCode());
        } else {
            bean.setCourseStatus(courseAuditDTO.getCourseStatus());
        }
        updateById(bean);
        fullAuditLog(courseAuditDTO);
    }

    /**
     * 条件分页查询课程库--只有管理员与学校有功能
     *
     * @param queryInfo 查询信息
     * @return 课程信息
     */
    @Override
    public PageInfo<CoursePageVO> listCourseLibrary(CourseQueryInfo queryInfo) {
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        //教育局/机构则直接返回空数据
        if (loginUser.getRoleId() == UserRoleEnum.ORGAN.getCode() || loginUser.getRoleId() == UserRoleEnum.EDUCATION.getCode()) {
            return new PageInfo<>();
        }
        //学校查找自己加入课程库的课程
        if (loginUser.getRoleId() == UserRoleEnum.SCHOOL.getCode()) {
            //  queryInfo.setCourseLibraryCreateId(loginUser.getUserId());
        }
        //运营/管理员
        if (loginUser.getRoleId() == UserRoleEnum.MANAGER.getCode() || loginUser.getRoleId() == UserRoleEnum.EDUCATION.getCode()) {
            // queryInfo.setCurrentAreaId(loginUser.getAreaId());
            queryInfo.setCurrentRoleId(loginUser.getRoleId());
            setChildAreaList(queryInfo);
        }
        return BasePage.queryBasePage(queryInfo, params -> this.getBaseMapper().queryCourseLibraryCount(params),
                params -> this.getBaseMapper().queryCourseLibraryList(params));
    }

    /**
     * 课程类型统计
     *
     * @return
     */
    @Override
    public List<CoursePieReportVO> courseReport() {
        Integer currentRoleId = UserUtil.getLoginUser().getRoleId();
        Integer currentAreaId = UserUtil.getLoginUser().getAreaId();
        List<SimpleCourseVO> retList = new ArrayList<>();
        //教育局查看教育局下的
        if (currentRoleId == UserRoleEnum.EDUCATION.getCode()) {
            retList = getBaseMapper().courseReport(null, currentAreaId);
            //管理员查看管理员下的
        } else if (currentRoleId == UserRoleEnum.EDUCATION.getCode()) {
            retList = getBaseMapper().courseReport(currentRoleId, null);
        }

        //查询出所有课程类目信息（层级）
        List<CategoryTreeVO> categoryTreeVOS = categoryService.treeCategory();

        List<CoursePieReportVO> courseReportVOS = new ArrayList<>();

        //如果查询出来的课程分类为空，则默认都是0
        if (CollUtil.isEmpty(retList)) {
            for (CategoryTreeVO categoryTreeVO : categoryTreeVOS) {
                CoursePieReportVO courseReportVO = new CoursePieReportVO();
                courseReportVO.setName(categoryTreeVO.getCategoryName());
                courseReportVO.setValue(0);
                courseReportVO.setCategoryId(String.valueOf(categoryTreeVO.getCategoryId()));
                courseReportVOS.add(courseReportVO);
            }
        } else {
            if (CollUtil.isNotEmpty(categoryTreeVOS)) {
                for (CategoryTreeVO categoryTreeVO : categoryTreeVOS) {
                    int temp = 0;
                    List<CategoryTreeVO> secondCategory = categoryTreeVO.getChildList();
                    if (CollUtil.isNotEmpty(secondCategory)) {
                        for (CategoryTreeVO categoryTreeVOSecond : secondCategory) {
                            List<CategoryTreeVO> thirdCategory = categoryTreeVOSecond.getChildList();
                            if (CollUtil.isNotEmpty(thirdCategory)) {
                                for (CategoryTreeVO categoryTreeVOThird : thirdCategory) {
                                    for (SimpleCourseVO simpleCourseVO : retList) {
                                        String categoryId = simpleCourseVO.getCourseCategoryId();
                                        if (categoryId.split(",")[2].equals(String.valueOf(categoryTreeVOThird.getCategoryId()))) {
                                            temp = temp + 1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    CoursePieReportVO courseReportVO = new CoursePieReportVO();
                    courseReportVO.setName(categoryTreeVO.getCategoryName());
                    courseReportVO.setValue(temp);
                    courseReportVO.setCategoryId(String.valueOf(categoryTreeVO.getCategoryId()));
                    courseReportVOS.add(courseReportVO);
                }
            }
        }
        return courseReportVOS;
    }

    /**
     * 获取课程审核失败原因
     *
     * @param courseId 课程id
     * @return string
     */
    @Override
    public String getCourseAuditMessage(Long courseId) {
        QueryWrapper<CourseAuditLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CourseAuditLog::getCourseId, courseId).orderByDesc(CourseAuditLog::getUpdateTime).last("limit 1");
        CourseAuditLog courseAuditLog = courseAuditLogService.getOne(queryWrapper);
        return courseAuditLog.getRemarks();
    }

    /**
     * 根据学校id查询对应的入驻机构数量
     *
     * @param schoolId
     * @return
     */
    @Override
    public List<OrganReportVO> getOrganCount(Long schoolId) {
        //获取通过申请的机构信息集合
        List<OrganReportVO> list = courseTeachingService.getOrganList(schoolId);
        if (CollUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        return list;
    }

    /**
     * 根据创建人id（学校id）查询对应的开课数量
     *
     * @param createId
     * @return
     */
    @Override
    public List<CourseReportVO> getCourseCount(Long createId) {
//        List<CourseReportVO> courseReportVOS = classService.getCourseCount(createId);
//        if (CollUtil.isEmpty(courseReportVOS)) {
//            return new ArrayList<>();
//        }
//        return courseReportVOS;
        return null;
    }

    /**
     * 课程课节列表
     *
     * @param courseId 课程id
     * @return List<CourseContentVO>
     */
    @Override
    public List<CourseContentVO> listCourseLessons(Long courseId) {
        List<CourseContentVO> courseContentList = new ArrayList<>();
        //根据课程内容id查询对应的课程内容（可能有多条，用集合接收）
        QueryWrapper<CourseLessons> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CourseLessons::getCourseId, courseId);
        List<CourseLessons> contentList = courseLessonsService.list(queryWrapper);
        if (CollUtil.isNotEmpty(contentList)) {
            contentList.forEach(punchCourseContent -> {
                CourseContentVO courseContentVO = new CourseContentVO();
                courseContentVO.setLessonsTitle(punchCourseContent.getLessonsTitle());
                courseContentVO.setLessonsContent(punchCourseContent.getLessonsContent());
                courseContentList.add(courseContentVO);
            });
        }
        return courseContentList;
    }

    /**
     * 根据课程类型名称获取学校开课详情列表
     *
     * @param categoryName 课程id
     * @return List<ClassesVO>
     */
    @Override
    public List<ClassesVO> coursesDetailReport(String categoryName) {
        //根据课程分类名称查询课程分类id
        List<CourseCategroy> categroys = categoryService.findCategoryIdByName(categoryName);
        if (CollUtil.isEmpty(categroys)) {
            return new ArrayList<>();
        }
        Long categoryId = categroys.get(0).getId();
        //根据课程分类id查询出课程详情列表
        List<ClassesVO> courseReportVOS = feignClassService.getClasses(categoryId);
        return courseReportVOS;
    }

    /**
     * 插入课程节数内容
     *
     * @param courseId          课程id
     * @param courseContentList 课程节数内容列表
     */
    private void insertCourseContent(Long courseId, List<CourseLessonsDTO> courseContentList) {
        List<CourseLessons> saveList = new ArrayList<>();
        //保存课程内容信息
        courseContentList.forEach(courseLessonsDTO -> {
            if (!StrUtil.isEmpty(courseLessonsDTO.getLessonsTitle()) || !StrUtil.isEmpty(courseLessonsDTO.getLessonsContent())) {
                CourseLessons punchCourse = new CourseLessons();
                punchCourse.setLessonsTitle(courseLessonsDTO.getLessonsTitle());
                punchCourse.setLessonsContent(courseLessonsDTO.getLessonsContent());
                punchCourse.setCourseId(courseId);
                saveList.add(punchCourse);
            }

        });
        courseLessonsService.saveBatch(saveList);
    }

    /**
     * 特殊处理  适用年级与上课周期
     *
     * @param punchCourse 课程实体
     * @param courseDTO   课程
     */
    private void handlerGrade(PunchCourse punchCourse, CourseDTO courseDTO) {
        //课程类目id 特殊处理
        if (CollUtil.isNotEmpty(courseDTO.getCourseCategoryId())) {
            StringBuilder sb = new StringBuilder();
            courseDTO.getCourseCategoryId().forEach(categoryId -> {
                sb.append(categoryId).append(",");
            });
            sb.deleteCharAt(sb.length() - 1);
            punchCourse.setCourseCategoryId(sb.toString());
        }
        //适用年级 courseGrade
        if (CollUtil.isNotEmpty(courseDTO.getCourseGrade())) {
            StringBuilder sb = new StringBuilder();
            courseDTO.getCourseGrade().sort(Comparator.naturalOrder());//排序下
            courseDTO.getCourseGrade().forEach(courseGrade -> sb.append(courseGrade).append(","));
            sb.deleteCharAt(sb.length() - 1);
            punchCourse.setCourseGrade(sb.toString());
        }
    }

    /**
     * @param newStatus     即将更改状态
     * @param oldStatus     本身状态
     * @param currentRoleId 当前用户角色id
     */
    private void verifyStatus(Integer newStatus, Integer oldStatus, Integer currentRoleId) {
        //判断当前用户是否是运营人员还是机构,机构只能提交教师 运营人员审核教师，需要做验证
//        if (!(currentRoleId == UserRoleEnum.EDUCATION.getCode()
//                || currentRoleId == UserRoleEnum.ORGAN.getCode())) {
//            throw new BusinessException(CourseExceptionEnum.AUDIT_ERROR.getCode(), "只有教育局/机构才能进行审核操作");
//        }
        //不做太多控制状态

        //2者一致,说明状态错误
        if (oldStatus.equals(newStatus)) {
            throw new BusinessException(CourseExceptionEnum.AUDIT_ERROR);
        }
//        //已经审核不能在审核
//        if (oldStatus == AuditStatusEnum.PASSED.getCode()) {
//            throw new BusinessException(UserExceptionEnum.AUDIT_ERROR.getCode(), "该机构已审核");
//        }
//
//        //0状态说明机构还没提交该老师
//        if (oldStatus == AuditStatusEnum.TO_AUDIT.getCode()) {
//            throw new BusinessException(UserExceptionEnum.AUDIT_ERROR.getCode(), "该机构暂未提交审核");
//        }
    }


    private void fullAuditLog(CourseAuditDTO courseAuditDTO) {
        CourseAuditLog bean = new CourseAuditLog();
        bean.setAuditStatus(courseAuditDTO.getCourseStatus());
        bean.setAuditTime(LocalDateTime.now());
        bean.setCourseId(courseAuditDTO.getCourseId());
        bean.setAuditor(UserUtil.getLoginUser().getUserId());
        bean.setRemarks(courseAuditDTO.getRemarks());
        courseAuditLogService.save(bean);
    }

    private void setChildAreaList(CourseQueryInfo queryInfo) {
        //查找该地区id下的子id
//        List<Long> childAreaIdList = feignAreaService.listFeignChildId(queryInfo.getCurrentAreaId());
//        if (CollUtil.isEmpty(childAreaIdList)) {
//            childAreaIdList = new ArrayList<>();
//        } else {
//            queryInfo.setChildAreaIdList(childAreaIdList);
//        }
//        childAreaIdList.add(queryInfo.getCurrentAreaId());
//        queryInfo.setChildAreaIdList(childAreaIdList);
    }
}





